package com.lai.shop.controller;


import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lai.shop.entity.ProductEntity;
import com.lai.shop.service.ProductService;
import com.lai.shop.utils.PageUtils;
import com.lai.shop.utils.R;



/**
 *
 *
 * @author laiciqi
 * @email 602469238@qq.com
 * @date 2022-05-19 13:16:52
 */
@RestController
@RequestMapping("/product")
@Api(value = "商品模块",tags = "商品模块")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions(":product:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions(":product:info")
    public R info(@PathVariable("id") Long id){
		ProductEntity product = productService.getById(id);

        return R.ok().put("product", product);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions(":product:save")
    public R save(@RequestBody ProductEntity product){
		productService.save(product);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions(":product:update")
    public R update(@RequestBody ProductEntity product){
		productService.updateById(product);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions(":product:delete")
    public R delete(@RequestBody Long[] ids){
		productService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    @PostMapping("/getProductList")
    public R getProductList(@RequestBody Map<String,Object> params){
        PageUtils page = productService.getProductList(params);
        return R.ok().put("data",page);
    }

}
